package com.mapper;

import com.domain.BlogComment;
import com.domain.Comment;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CommentMapper {
    //通过文章id删除评论信息
    @Delete("DELETE FROM t_comment WHERE article_id =#{aid} ")
    public Comment deleteCommentWithId(Integer aid);

    //分页展示某个文章的评论
    @Select("SELECT * FROM t_comment WHERE article_id=#{aid} ORDER BY id DESC ")
    public List<BlogComment> selectCommentWithPage(Integer aid);

    //后台查询最新几条评论
    @Select("SELECT * FROM t_comment ORDER BY id DESC ")
    public List<BlogComment> selectNewComment();

    //发表评论
    @Insert("INSERT INTO t_comment (article_id,created,author,ip,content) " + "values (#{articleId},#{created},#{author},#{ip},#{content}) ")
    public void pushComment(BlogComment comment);

    //站点服务统计，统计评论数量
    @Select("SELECT COUNT(1) FROM t_comment ")
    public Integer countComment();
    //获取评论列表
    @Select("SELECT t.*,a.title articleTitle FROM t_comment t,t_article a WHERE t.article_id=a.id ORDER BY t.id DESC ")
    public List<BlogComment> selectComment();

    void deleteComment(int id);
//    @Update("UPDATE t_commemt SET content=#{content} WHERE id=#{id}")
//    public int updareComment(Comment comment);
//
//    @Delete("DELETE FROM t_comment WHERE id=#{id}")
//    public int deleteComment(Integer id);
}
